<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>规格列表</title>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/layui@2.6.8/dist/css/layui.css">
    <script src="//cdn.jsdelivr.net/npm/layui@2.6.8/dist/layui.js" charset="utf-8"></script>
</head>

<body>
    <div style="margin: 15px;padding: 15px;background-color: #fff;">
        <div style="text-align: right;">
            <a class="layui-btn layui-btn-xs layui-btn-primary" href="/admins/products/index">返回</a>
            <button class="layui-btn layui-btn-xs" onclick="add({$product['id']})">添加</button>
        </div>

        <table class="layui-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>商品编码</th>
                    <th>商品名称</th>
                    <th>规格名称</th>
                    <th>商品价格</th>
                    <th>库存</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach $lists as $list}
                <tr>
                    <td>{$list['id']}</td>
                    <td>{$list['out_no']}</td>
                    <td>{$product['title']}</td>
                    <td>{$list['sku_title']}</td>
                    <td>{$list['price']}</td>
                    <td>{$list['stock']}</td>
                    <td>{$list['status'] ? '<span style="color:red;">下架</span>' : '<span
                            style="color: green;">正常</span>'}</td>
                    <td>
                        <a href="/product/detail.html?out_no={$list['out_no']}" class="layui-btn layui-btn-xs layui-btn-primary" target="_blank">详情</a>
                        <button class="layui-btn layui-btn-xs" onclick="edit({$list['id']})">编辑</button>
                        <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del({$list['id']})">删除</button>
                    </td>
                </tr>
                {/foreach}
            </tbody>
        </table>
    </div>

    <script>
        var $ = layui.jquery;

        function add(pro_id) {
            window.location.href = '/admins/products/add_sku?pro_id='+ pro_id;
        }

        function edit(id) {
            var index = layer.open({
              type: 2,//1 dom或文本，2 iframe,3 加载层,4 tips
              shadeClose:true,
              maxmin: true,
              area: ['480px', '450px'],
              title: '修改商品规格',
              content: '/admins/products/edit_sku?id='+ id
            });
            layer.full(index);
        }

        function del(id) {
            layer.confirm('确定删除吗？', { icon: 3 }, function () {
                $.post('/admins/products/delete_sku', { id }, function (res) {
                    if (res.code) return layer.alert(res.msg, { icon: 2 });
                    layer.alert(res.msg, { icon: 1 });
                    setTimeout(() => window.location.reload(), 1000);
                }, 'json');
            });
        }
    </script>
</body>

</html>